__author__ = 'pcJxy'

from rsa import *
from utils.codec_utils import *


def main():
    """
    This function calls RSA key generation progress, and writes the keys into files.

    :return:
    """
    e, n, d = rsa_keygen()
    e_b64str = int_2_b64str(e)
    n_b64str = int_2_b64str(n)
    d_b64str = int_2_b64str(d)
    private_key_file = open("rsa_private.key", "w")
    public_key_file = open("rsa_public.key", "w")
    public_n_file = open("rsa_n.key", "w")
    for i in range(0, len(e_b64str), 64):
        public_key_file.write(e_b64str[i:i + 64] + '\n')
    for i in range(0, len(n_b64str), 64):
        public_n_file.write(n_b64str[i:i + 64] + '\n')
    for i in range(0, len(d_b64str), 64):
        private_key_file.write(d_b64str[i:i + 64] + '\n')
    public_key_file.close()
    public_n_file.close()
    private_key_file.close()


if __name__ == '__main__':
    main()
